﻿using IntelligentAgriculture.Contracts.Interface;
using IntelligentAgriculture.Domain.Entity;
using IntelligentAgriculture.WebAPI.Application.Command.DeathModelCommand;
using IntelligentAgriculture.WebAPI.Application.Command.EarTageCommand;
using MediatR;

namespace IntelligentAgriculture.WebAPI.Application.CommandHandler.DeathModelCommandHamdier
{
    public class DeathEagUpdateCommandHandler : IRequestHandler<DeathEagUpdateCommand, Results<int>>
    {
        private readonly iDeathModelService _iDeathModelService;

        public DeathEagUpdateCommandHandler(iDeathModelService deathModelService)
        {
            _iDeathModelService = deathModelService;
        }
        /// <summary>
        /// 处理死亡鹰更新命令
        /// </summary>
        /// <param name="request">死亡鹰更新命令请求</param>
        /// <param name="cancellationToken">取消标记</param>
        /// <returns>表示异步操作结果的任务。</returns>
        public async Task<Results<int>> Handle(DeathEagUpdateCommand request, CancellationToken cancellationToken)
        {
            var entity = new Deathmodel()
            {
                SheepRescissionSex = request.SheepRescissionSex,
                ReproductiveState = request.ReproductiveState,
                BirthDate = request.BirthDate,
                BuildingManagementId = request.BuildingManagementId,
                ColumnManagementId = request.ColumnManagementId,
                CreateBy = request.CreateBy,
                CreateDate = request.CreateDate,
                DeathDate = request.DeathDate,
                DeathId = request.DeathId,
                DeathType = request.DeathType,
                EarTag = request.EarTag,
                LogicalDeletion = request.LogicalDeletion,
                UpdateBy = request.UpdateBy,
                UpdateDate = request.UpdateDate,
                Variety = request.Variety,
            };

            var list = await _iDeathModelService.UpateEartag(entity);
            return Results<int>.DataResult(list);
        }
    }
}
